import java.util.Calendar;


public class ServicedJob implements IServicedJob
{
	private IJob job = null;
	
	private int start_hour;
	private int start_minute;
	private int start_second;
	
	private int finish_hour = 0;
	private int finish_minute = 0;
	private int finish_second = 0;
	
	private Double powerConsumed = null;
	
	public ServicedJob(IJob job, Calendar startInstance, Double pC)
	{
		this.job = job;
		this.start_hour = startInstance.get(Calendar.HOUR_OF_DAY);
		this.start_minute = startInstance.get(Calendar.MINUTE);
		this.start_second = startInstance.get(Calendar.SECOND);
		this.powerConsumed = pC;
		
		calculateFinishTime();
	}
	
	private void calculateFinishTime()
	{
		int givenSeconds = job.getDuration();
		
		int extraSeconds = (int) (givenSeconds % 60);
		int extraMinutes = (int) ( (int) (givenSeconds/60) % 60);
		int extraHours = (int) (givenSeconds/3600);
		
		finish_hour = start_hour + extraHours;
		finish_minute = start_minute + extraMinutes;
		finish_second = start_second + extraSeconds;
	}
	
	public IJob getJob()
	{
		return job;
	}
	
	public Double getPowerConsumed()
	{
		return powerConsumed;
	}
	
	public boolean isJobOver(Calendar currentInstance)
	{		
		if((currentInstance.get(Calendar.HOUR_OF_DAY) >= finish_hour) 
				&& (currentInstance.get(Calendar.MINUTE) >= finish_minute) 
				&& (currentInstance.get(Calendar.SECOND) >= finish_second))
		{
			return true;
		}
			
		return false;
	}
}
